import java.time.*;

public class Billing {
    private static final double INIT_RATE = 0.05; // 初始费率（单位：美元/分钟）
    private static final double ADDITIONAL_RATE = 0.10; // 每增加一分钟的费率（单位：美元/分钟）
    private static final double LONG_CALL_RATE = 1.00; // 长通话费率（单位：美元）
    private static final int SHORT_CALL_MINUTES = 20; // 短通话最大分钟数
    private static final int MAX_MINUTES = 1800;//不能超过30小时

    public static double calculateCost( final  LocalDateTime startTime, final LocalDateTime endTime) {
        ZonedDateTime startZonedTime = convertToZonedDateTime(startTime);
        ZonedDateTime endZonedTime = convertToZonedDateTime(endTime);

        double totalCost = 0.0;
        long minutes = getMinutesBetween(startZonedTime, endZonedTime);
        if (minutes == 0) {
            return INIT_RATE;
        }
        else if (minutes <= SHORT_CALL_MINUTES) {
            totalCost += INIT_RATE * Math.ceil(minutes); // 不足1分钟按1分钟计算
        }
        else if(minutes >SHORT_CALL_MINUTES && minutes<=MAX_MINUTES) {
            totalCost += INIT_RATE * SHORT_CALL_MINUTES;
            totalCost += (minutes - SHORT_CALL_MINUTES) * ADDITIONAL_RATE; // 超过20分钟的部分每分钟0.10美元
            totalCost += LONG_CALL_RATE; // 长通话费率
        }
        else {
            totalCost=-1;
        }


        return totalCost;
    }

    private static ZonedDateTime convertToZonedDateTime(LocalDateTime dateTime) {
        ZoneId EST = ZoneId.of("America/New_York");
        return ZonedDateTime.of(dateTime, EST);
    }

    private static long getMinutesBetween(ZonedDateTime start, ZonedDateTime end) {
        return Math.round((end.toEpochSecond() - start.toEpochSecond()) / 60.0);
    }
}
